<template>
  <div>
    <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="id"
          label="编号"
          width="80">
      </el-table-column>
      <el-table-column
          prop="orderNo"
          label="订单号"
          width="120">
      </el-table-column>
      <el-table-column
          prop="uid"
          label="用户ID"
          width="120">
      </el-table-column>
      <el-table-column
          prop="addrId"
          label="地址ID"
          width="120">
      </el-table-column>
      <el-table-column
          prop="amount"
          label="付款金额"
          width="120">
      </el-table-column>
      <el-table-column
          prop="type"
          label="付款类型"
          width="120">
      </el-table-column>
      <el-table-column
          prop="freight"
          label="运费"
          width="120">
      </el-table-column>
      <el-table-column
          prop="status"
          label="订单状态"
          width="120">
      </el-table-column>
      <el-table-column
          prop="createTime"
          label="创建时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="updateTime"
          label="更新时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="deliveryTime"
          label="发货时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="finishTime"
          label="完成时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="paymentTime"
          label="付款时间"
          width="120">
      </el-table-column>
      <el-table-column
          prop="closeTime"
          label="关闭时间"
          width="120">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="details(scope.row)" type="text" size="small">详情</el-button>
          <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        page-size="5"
        :total="total"
        @current-change="page">
    </el-pagination>
    <el-dialog title="订单详情" :visible.sync="dialogTableVisible">
      <el-table :data="tableData2">
        <el-table-column property="id" label="商品编号"></el-table-column>
        <el-table-column property="name" label="商品名称"></el-table-column>
        <el-table-column property="specParam" label="规格参数"></el-table-column>
        <el-table-column property="price" label="价格"></el-table-column>
        <el-table-column property="quantity" label="数量"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
export default {
  methods: {
    del(row){
      const _this=this;
      this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.post('http://localhost:8181/order/deleteOrder/'+row.orderNo).then(function(resp){
          if(resp.data==0){
            _this.$message.error('删除失败!');
          }else{
            _this.$message({
              type: 'success',
              message: '删除成功!'
            });
            window.location.reload();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    details(row) {
      this.dialogTableVisible = true
      const id=row.orderNo;
      const _this=this;
      console.log(id);
      axios.get('http://localhost:8181/order/findByOrderNo/'+id).then(function(resp){
        console.log(resp.data);
        _this.tableData2=resp.data.data
      })
    },
    page(currentPage){
      const _this=this;
      axios.get('http://localhost:8181/order/findAllOrders/'+currentPage+'/'+5).then(function(resp){
        _this.tableData=resp.data.data
        _this.total=resp.data.totalNum
        _this.loading=false
      })
    }
  },
  created() {
    const _this=this;
    axios.get('http://localhost:8181/order/findAllOrders/'+1+'/'+5).then(function(resp){
      _this.tableData=resp.data.data
      _this.total=resp.data.totalNum
      _this.loading=false
    })
  },
  data() {
    return {
      total:null,
      tableData:null,
      tableData2:null,
      dialogTableVisible: false,
      loading: true
    }
  }
}
</script>

<style scoped>

</style>